#include <iostream>
#include <string>
#include <sstream>
#include <vector>

using namespace std;

string reverseStr(string s)
{
	int i = 0, j = s.length() - 1;
	while (i < j)
	{
		swap(s[i], s[j]);
		++i;
		--j;
	}
	return s;
}

string reverseStr(string s,int i, int j)
{
	while (i < j)
	{
		swap(s[i], s[j]);
		++i;
		--j;
	}
	return s;
}

string ReverseSentence(string str) {
	if (str.find_first_not_of(" ") == string::npos) return str;
	string rStr = reverseStr(str);
	istringstream stream(rStr);
	ostringstream os;
	string word;
	while (stream >> word)
	{
		os << reverseStr(word) << " ";
	}
	string re = os.str();
	return re.substr(0, re.length() - 1);
	
}

//int main()
//{
//	string s = " ";
//	string re = ReverseSentence(s); 
//	
// 	cout << re;
//
//	system("pause");
//	return 0;
//}